<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<?php
$Tag = M('CourseProject');
$re2 = $Tag->where(array('id'=>I('get.id')))->select();
foreach ($re2 as $list2) {
?>
<form id="myForm" action="http://www.admin.com/CourseProject/createCourseProject?id=<?=$list2[id]?>" method="post">

    名称：<input type="text" name="name"  value="<?=$list2[name] ?>"><div id="message"></div><br>

    <input type="submit" id="submit" value="提交">
</form>
<?php } ?>
<script>
    var submitButton=document.getElementById('submit');
    var messageElement=document.getElementById('message');
    var myFormElement=document.getElementById('myForm');
    submitButton.onclick=function(e) {
            e.preventDefault();
            var titleElement = document.querySelector('#myForm input[name=name]');
            var name = titleElement.value;
            if (name == "") {
                messageElement.innerHTML = '名称不能为空';
                return;
            };
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (this.readyState == 4) {
                    if (this.status == 200) {
                        var result = JSON.parse(this.responseText);
                        if (result.error == 1) {
                            messageElement.innerHTML = result.message;
                        } else {
                            location.href = 'http://www.admin.com/Index/index';
                        }
                    } else {
                        console.log("异常");
                    }
                }
            };
            xhr.open(myFormElement.method, myFormElement.action);
            var data = new FormData();
            data.append('name',name);
            xhr.send(data);
        }
</script>
</body>
</html>